package com.sigmatrix.h5.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sigmatrix.h5.dao.DisRebateScanCodeErrorDao;
import com.sigmatrix.h5.entity.DisRebateScanCodeError;
import com.sigmatrix.h5.service.DisRebateScanCodeErrorService;
import com.sigmatrix.h5.service.DisRebateScanCodeService;
import com.sigmatrix.h5.utils.CommonUtils;
import com.sigmatrix.h5.web.args.DealerInventoryPageParam;
import com.sigmatrix.h5.web.mode.DealerInventoryDayCount;
import com.sigmatrix.h5.web.mode.DealerInventoryError;
import com.sigmatrix.h5.web.mode.ErrorInfo;
import com.sigmatrix.sc.jdbc.common.service.ServiceImpl;
@Service
public class DisRebateScanCodeErrorServiceImpl extends ServiceImpl<DisRebateScanCodeError,Integer> implements DisRebateScanCodeErrorService {
	
	@Autowired
	private DisRebateScanCodeErrorDao disRebateScanCodeErrorDao;
	
	@Autowired
	private DisRebateScanCodeService disRebateScanCodeService;
	
	@Override
	public void save(DisRebateScanCodeError error) {
		disRebateScanCodeErrorDao.insertSelective(error);
	}


	@Override
	public List<DealerInventoryDayCount> findDayCountList(DealerInventoryPageParam vo) {
		return disRebateScanCodeErrorDao.findDayCountList(vo);
	}


	@Override
	public List<ErrorInfo> findInfoList(DealerInventoryPageParam vo) {
		return disRebateScanCodeErrorDao.findInfoList(vo);
	}


	@Override
	public DealerInventoryError findDealerInventoryError(DealerInventoryPageParam vo) {
		DealerInventoryError error = new DealerInventoryError();
		List<DealerInventoryDayCount> listDayErrors = findDayCountList(vo);
		if(CommonUtils.isNotEmpty(listDayErrors)) {
			error.setErrorCount(listDayErrors.get(0).getCount()==null ?0:listDayErrors.get(0).getCount());
		}
		List<DealerInventoryDayCount> listDaySuccess =  disRebateScanCodeService.findDayCount(vo);
		if(CommonUtils.isNotEmpty(listDaySuccess)) {
			error.setSuccessCount(listDaySuccess.get(0).getCount() == null ? 0 : listDaySuccess.get(0).getCount());
		}
		List<ErrorInfo> infos = findInfoList(vo);
		error.setInfos(infos);
		return error;
	}

}
